package com.sqfw.project.largeScreen.controller;

import com.sqfw.framework.web.controller.BaseController;
import com.sqfw.framework.web.domain.AjaxResult;
import com.sqfw.framework.web.page.TableDataInfo;
import com.sqfw.project.knowledge.domain.KlContentInfo;
import com.sqfw.project.knowledge.service.KlContentService;
import com.sqfw.project.largeScreen.domain.query.LargeScreenQuery;
import com.sqfw.project.largeScreen.service.LargeScreenService;
import com.sqfw.project.system.domain.SysDictData;
import com.sqfw.project.wp.domain.WpInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 大屏幕的接口
 *
 * @author tangxt
 * */
@Api(tags = "大屏幕接口")
@Slf4j
@RestController
@RequestMapping("/largeScreen/")
public class LargeScreenController extends BaseController {

    @Autowired
    private LargeScreenService largeScreenService;

    @Autowired
    private KlContentService klContentService;

    /**
     * 根据二级业务分类，三级业务分类，五大板块分类，统计工单数量
     * 每个统计只展示5条
     * @param query
     * @return
     */
    @ApiOperation("根据二级业务分类，三级业务分类，统计工单数量")
    @PostMapping("countWpByCode")
    public AjaxResult countWpByClassify(@RequestBody LargeScreenQuery query) {
        if (query.getTimeLevel() == null) {
            return AjaxResult.error("时间等级必传！");
        }
        return largeScreenService.countWpByClassify(query);
    }

    /**
     * 五大板块分类，统计工单数量
     * */
    @ApiOperation("根据五大板块分类，统计工单数量")
    @PostMapping("countWpByFiveMajorModules")
    public AjaxResult countWpByFiveMajorModules(@RequestBody LargeScreenQuery query) {
        if (query.getTimeLevel() == null) {
            return AjaxResult.error("时间等级必传！");
        }
        return largeScreenService.countWpByFiveMajorModules(query);
    }

    /**
     *  查询10条 知识库数据，根据修改时间排序
     * @param query
     * @return
     * */
    @ApiOperation("查询20条 知识库数据，根据修改时间排序")
    @GetMapping("queryLargeScreenKnowledge")
    public TableDataInfo queryLargeScreenKnowledge(LargeScreenQuery query) {
        startPage();
        List<KlContentInfo> list = largeScreenService.queryLargeScreenKnowledge(query);
        return getDataTable(list);
    }

    /**
     * 查询知识形式，知识来源
     * @param type 字典类型
     * @return
     * */
    @ApiOperation("查询知识形式，知识来源")
    @GetMapping("getKnowledgeShapeList")
    public AjaxResult getKnowledgeShapeList(@RequestParam("type") String type) {
        SysDictData dictData = new SysDictData();
        dictData.setDictType(type);
        List<SysDictData> sysDictDataList = klContentService.getKnowledgeShapeList(dictData);
        if (CollectionUtils.isEmpty(sysDictDataList)) {
            return AjaxResult.error("没有数据");
        }
        return AjaxResult.success(sysDictDataList);
    }


    /**
     * 根据id查询知识数据
     * @param klId 知识表id
     * @return
     * */
    @ApiOperation("根据id查询知识数据")
    @GetMapping("queryKlContentInfoByKlId")
    public AjaxResult queryKlContentInfoByKlId(@RequestParam("klId") String klId){
        KlContentInfo klContentInfo = klContentService.queryKlContentInfoByKlId(klId);
        if (klContentInfo == null) {
            return AjaxResult.error("没有知识数据");
        }
        return AjaxResult.success(klContentInfo);
    }


    /**
     * 统计12345工单总数，社区服务自办件，工单总数，建单数，呼出数
     * @param query
     * @return
     * */
    @ApiOperation("统计12345工单总数，社区服务自办件，工单总数，建单数，呼出数")
    @PostMapping("countWpTotal")
    public AjaxResult countWpTotal(@RequestBody LargeScreenQuery query) {
        if (query.getTimeLevel() == null) {
            return AjaxResult.error("时间等级必传！");
        }
        return largeScreenService.countWpTotal(query);
    }

    /**
     * 根据主办单位分组统计
     * @param query
     * @return
     * */
    @ApiOperation("根据主办单位分组统计")
    @PostMapping("countWpByMainUnit")
    public AjaxResult countWpByMainUnit(@RequestBody LargeScreenQuery query) {
        if (query.getTimeLevel() == null || StringUtils.isBlank(query.getMainUnitLike())) {
            return AjaxResult.error("时间等级/主办单位必传！");
        }
        return largeScreenService.countWpByMainUnit(query);
    }


    /**
     * 统计超时，不满意统计总数
     * @param query
     * @return
     * */
    @ApiOperation("统计超时，不满意统计总数")
    @PostMapping("countTimeoutAndDissatisfied")
    public AjaxResult countTimeoutAndDissatisfied(@RequestBody LargeScreenQuery query) {
        if (query.getTimeLevel() == null || StringUtils.isBlank(query.getMainUnitLike())
                || query.getCountNumber() == null) {
            return AjaxResult.error("时间等级/主办单位/统计数量必传！");
        }
        return largeScreenService.countTimeoutAndDissatisfied(query);
    }


    /**
     * 统计回访不同情况的数据量
     * @param query
     * @return
     * */
    @ApiOperation("统计回访不同情况的数据量")
    @PostMapping("countWpVisitInfoByGrouping")
    public AjaxResult countWpVisitInfoByGrouping(@RequestBody LargeScreenQuery query) {
        if (query.getTimeLevel() == null) {
            return AjaxResult.error("时间等级必传！");
        }
        return largeScreenService.countWpVisitInfoByGrouping(query);
    }

    /**
     * 实时工单
     * @param query
     * @return
     * */
    @ApiOperation("实时工单")
    @GetMapping("getRealTimeWpInfoList")
    public TableDataInfo getRealTimeWpInfoList(LargeScreenQuery query) {
        startPage();
        List<WpInfo> list = largeScreenService.getRealTimeWpInfoList(query);
        return getDataTable(list);
    }

    /**
     * 大屏幕重新知识库
     * @param klContentInfo
     * @return
     * */
    @GetMapping("queryLargeScreenlContentInfoList")
    public TableDataInfo queryLargeScreenlContentInfoList(KlContentInfo klContentInfo) {
        List<KlContentInfo> list = klContentService.queryHomeKlContentInfoList(klContentInfo);
        return getDataTable(list);
    }


}
